<?php if (!defined('THINK_PATH')) exit();?><!doctype html>
<html>
<head>
	<meta charset="utf-8">
	<!-- Set render engine for 360 browser -->
	<meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- HTML5 shim for IE8 support of HTML5 elements -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <![endif]-->

	<link href="/public/simpleboot/themes/<?php echo C('SP_ADMIN_STYLE');?>/theme.min.css" rel="stylesheet">
    <link href="/public/simpleboot/css/simplebootadmin.css" rel="stylesheet">
    <link href="/public/js/artDialog/skins/default.css" rel="stylesheet" />
    <link href="/public/simpleboot/font-awesome/4.4.0/css/font-awesome.min.css"  rel="stylesheet" type="text/css">
    <style>
		.length_3{width: 180px;}
		form .input-order{margin-bottom: 0px;padding:3px;width:40px;}
		.table-actions{margin-top: 5px; margin-bottom: 5px;padding:0px;}
		.table-list{margin-bottom: 0px;}
	</style>
	<!--[if IE 7]>
	<link rel="stylesheet" href="/public/simpleboot/font-awesome/4.4.0/css/font-awesome-ie7.min.css">
	<![endif]-->
<script type="text/javascript">
//全局变量
var GV = {
    DIMAUB: "/",
    JS_ROOT: "public/js/",
    TOKEN: ""
};
document.domain = "xinhuiwen.com";
</script>
<!-- Le javascript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="/public/js/jquery.js"></script>
    <script src="/public/js/wind.js"></script>
    <script src="/public/js/publish.js"></script>

    <script src="/public/simpleboot/bootstrap/js/bootstrap.min.js"></script>
<?php if(APP_DEBUG): ?><style>
		#think_page_trace_open{
			z-index:9999;
		}
	</style><?php endif; ?>
</head>
<body>
	<div class="wrap js-check-wrap">
		<ul class="nav nav-tabs">
			<li class="active"><a href="<?php echo U('Admin/Live/index');?>">直播列表</a></li>
			<li><a href="<?php echo U('Admin/Live/add');?>">添加直播</a></li>
		</ul>
		<form class="well form-search" id="query_form" method="post" action="<?php echo U('Admin/Live/index');?>">
			名称： 
			<input type="text" name="name" style="width: 120px;" value="<?php echo ($formParam["name"]); ?>" placeholder="直播名称...">
			类型：
			<select class="select_2" id="category" name="category" style="width: 90px;">
				<option value='-1'>全部</option>
				<option value='1' <?php if($formParam["category"] == 1): ?>selected<?php endif; ?>>视频直播</option>
				<option value='2' <?php if($formParam["category"] == 2): ?>selected<?php endif; ?>>VR直播</option>
				<option value='3' <?php if($formParam["category"] == 3): ?>selected<?php endif; ?>>图文直播</option>
				<option value='4' <?php if($formParam["category"] == 4): ?>selected<?php endif; ?>>视频加图文直播</option>
				<option value='5' <?php if($formParam["category"] == 5): ?>selected<?php endif; ?>>VR加图文直播</option>
				<!--<option value='6' <?php if($formParam["category"] == 6): ?>selected<?php endif; ?>>录播</option>-->
			</select>
			状态： 
			<select class="select_2" name="status" style="width: 90px;">
				<option value='-1'>全部</option>
				<option value='3' <?php if($formParam["status"] == 3): ?>selected<?php endif; ?>>未开始</option>
				<option value='2' <?php if($formParam["status"] == 2): ?>selected<?php endif; ?>>直播结束</option>
				<option value='4' <?php if($formParam["status"] == 4): ?>selected<?php endif; ?>>正在直播</option>
				<option value='5' <?php if($formParam["status"] == 5): ?>selected<?php endif; ?>>直播回顾</option>
			</select>
			<input type="button" name="query_form_btn" id="queryBtn" data-action="<?php echo U('Admin/Live/index');?>" class="btn btn-primary" value="查询" />
		</form>
		<form class="js-ajax-form" action="" method="post">
		<table class="table table-hover table-bordered">
			<thead>
				<tr>
					<th>名称</th>
					<th>类型</th>
					<th>开始时间</th>
					<th>URL</th>
					<th>排序日期</th>
					<th>状态</th>
					<th>观看人数</th>
					<?php if($user_can_show_count == 1): ?><th>真实观看人数</th><?php endif; ?>
					<th>权重</th>
					<th>创建者</th>
					<th>操作</th>
					<th>打赏列表</th>
				</tr>
			</thead>
			<tbody>
				<?php $status = array("2"=>'直播结束',"3"=>'未开始',"4"=>'正在直播',"5"=>'直播回顾'); ?>
				<?php if(is_array($data)): foreach($data as $key=>$vo): ?><tr>
					<td><?php echo ($vo["name"]); ?></td>
					<td><?php if($vo["category"] == 1): ?>视频直播<?php endif; ?>
					<?php if($vo["category"] == 2): ?>VR直播<?php endif; ?>
					<?php if($vo["category"] == 3): ?>图文直播<?php endif; ?>
					<?php if($vo["category"] == 4): ?>视频加图文直播<?php endif; ?>
					<?php if($vo["category"] == 5): ?>VR加图文直播<?php endif; ?>
					<?php if($vo["category"] == 6): ?>录播<?php endif; ?>
					</td>
					<td><?php echo ($vo['start_time']); ?></td>
					<td>id=<?php echo ($vo['live_id']); ?>&type=live
					<a style="float:right;" class="link_url" data-clipboard-text="id=<?php echo ($vo['live_id']); ?>&type=live" title="id=<?php echo ($vo['live_id']); ?>&type=live" href="javascript:;" >复制</a>
					</td>
					<td>
					<!-- <?php if($vo["red_score"] != null): echo ($vo["red_score"]); ?>（<?php echo ($vo["red_competitor"]); ?>）：<?php echo ($vo["blue_score"]); ?>（<?php echo ($vo["blue_competitor"]); ?>）<?php endif; ?> -->
					<!-- 直播列表刷新 排序时间 -->
					<?php echo ($vo['refresh_time']); ?>
						<?php if($admin_id == 1){?>
					<input type="button" id="refresh" value="刷新" onclick="refresh_news('<?php echo $vo['live_id'];?>')" class="btn btn-primary" style="float:right;">
						<?php } ?>
					</td>
					<td><?php echo ($status[$vo['status']]); ?></td>
					<td><input type="text" name="weight" id="weight<?php echo ($vo["live_id"]); ?>" value="<?php echo ($vo["play_count"]); ?>" disabled="disabled" size="2"  class="input_edit">
						<?php if($_SESSION['ADMIN_ID'] == 1): ?><a id="edit_weight_<?php echo ($vo["live_id"]); ?>" href='javascript:void(0);' onclick="update_live_count('<?php echo ($vo["live_id"]); ?>','live')" class="edit_sub">修改</a><?php endif; ?>
                        <input type="hidden" name="old_weight" id="old_weight_<?php echo ($vo["live_id"]); ?>" value="<?php echo ($vo["play_count"]); ?>">
                    </td>
                    <?php if($user_can_show_count == 1): ?><td><?php echo ($vo["true_play_count"]); ?></td><?php endif; ?>
					<!-- <td><?php echo ($vo['weight']); ?></td> -->
					<td><input type="text" name="live_weight" id="live_weight<?php echo ($vo["live_id"]); ?>" value="<?php echo ($vo["weight"]); ?>" disabled="disabled" size="2"  class="live_input_edit">
                        <a id="live_edit_weight_<?php echo ($vo["live_id"]); ?>" href='javascript:void(0);' onclick="update_weight('<?php echo ($vo["live_id"]); ?>','live')" class="live_edit_sub">修改</a>
                        <input type="hidden" name="live_old_weight" id="live_old_weight_<?php echo ($vo["live_id"]); ?>" value="<?php echo ($vo["weight"]); ?>">
                    </td>
                    <td><?php echo ($vo["creator_name"]); ?></td>
					<td>
					<?php if(in_array($vo['category'],array(3,4,5))): ?><a href='<?php echo U("Admin/LiveGraphic/live_panel", array("live_id"=>$vo["live_id"]));?>'>直播员面板</a><?php endif; ?>
						   <?php if($vo["type"] == 2): if($vo["status"] != 3): ?><a class="set_result" data-id="<?php echo ($vo["live_id"]); ?>" data-red-id="<?php echo ($vo["red_competitor_id"]); ?>" data-blue-id="<?php echo ($vo["blue_competitor_id"]); ?>" href='<?php echo U("Admin/Live/set_result", array("live_id"=>$vo["live_id"]));?>'>更新比分</a><?php endif; endif; ?>

						   <a href='<?php echo U("Admin/Live/edit", array("live_id"=>$vo["live_id"]));?>'>编辑</a>
						   <?php if($vo["status"] != 3): ?><a href='<?php echo U("Admin/Live/view", array("live_id"=>$vo["live_id"]));?>' >详情</a><?php endif; ?>

						   <?php if($vo["status"] != 4 and $admin_id == 1): ?><a href='<?php echo U("Admin/Live/delete", array("live_id"=>$vo["live_id"]));?>' class="js-ajax-dialog-btn">删除</a><?php endif; ?>
						   <a href='<?php echo U("Admin/Live/news_relation", array("live_id"=>$vo["live_id"]));?>'>相关文章</a>
							<!--<?php if($vo["is_fast"] == 0): ?>--><!--<?php endif; ?>-->
							<a href='<?php echo U("Admin/Live/direct_manage", array("live_id"=>$vo["live_id"],"is_fast"=>$vo["is_fast"]));?>'>导播管理</a>

						   <?php if($vo["status"] != 3): ?><a class="set_status" data-id="<?php echo ($vo["live_id"]); ?>" data-status="<?php echo ($vo["status"]); ?>" href='<?php echo U("Admin/Live/set_status", array("live_id"=>$vo["live_id"]));?>'>更新状态</a><?php endif; ?>
							<?php if($vo["quiz_status"] == 1): ?><a href='<?php echo U("Admin/Guest/index", array("live_id"=>$vo["live_id"]));?>'>竞猜管理</a><?php endif; ?>
							<?php if($vo["is_props"] != 0): ?><a href='<?php echo U("Admin/Prop/index", array("live_id"=>$vo["live_id"]));?>'>打赏管理</a><?php endif; ?>
					</td>
					<td><a href="<?php echo U('Admin/Live/live_reward_list',array( 'live_id'=>$vo['live_id']));?>" ><?php echo ($vo["hw_money_total"]); ?>汇闻币</a></td>
				</tr><?php endforeach; endif; ?>
			</tbody>
		</table>
		</form>
		<div class="pagination"><?php echo ($page); ?></div>
	</div>
	<script src="/public/js/common.js"></script>
	<script type="text/javascript" src="/public/js/ueditor/third-party/zeroclipboard/ZeroClipboard.min.js"></script>
	<script src="/public/js/layer/layer.js"></script>
	<script>
	$(document).ready(function(){
		$('input[name="query_form_btn"]').click(function(){
			 $('#query_form').attr('action', $(this).attr('data-action'));
			 $('#query_form').submit();
		});
		
		var clip = new ZeroClipboard($("td .link_url"));
		clip.on("aftercopy", function(e){
			layer.msg('复制成功！');
		    //alert('复制成功！');
		});
		$('#typeId').val(<?php echo ($formParam["typeId"]); ?>);
		
		$('.set_result').click(function(e){
			e.preventDefault();
			$_this = this;
			var live_id = $($_this).attr('data-id');
			var red_competitor_id = $($_this).attr('data-red-id');
			var blue_competitor_id = $($_this).attr('data-blue-id');
			
			$.getJSON('<?php echo U("Admin/Live/get_competitor");?>&red_competitor_id='+red_competitor_id+'&blue_competitor_id='+blue_competitor_id).done(function (data) {
	            if (data.state === 'success') {
	            	var href = $($_this).prop('href');
	            	var contentHtml = "<div style='width:220px;height:100px;padding:0px 10px;'><div style='width:80px;float:left;text-align:center;'><div style='width:80px; height:80px; border-radius:50%; overflow:hidden;'><img src="+
	            	                  data.info.red.avatar+" style='width:80px;height:80px;'></div><span>"+
	            	                  data.info.red.real_name+"</span></div><div style='width:80px;float:right;text-align:center;'><div style='width:80px; height:80px; border-radius:50%; overflow:hidden;'><img src="+
	            	                  data.info.blue.avatar+" style='width:80px;height:80px;'></div><span>"+
	            	                  data.info.blue.real_name+"</span></div><div style='width:220px;float:left;margin-top:10px;text-align:center;'><input id='red_score' style='width:75px;'><span style='font-family:Bold;font-weight:900;width:20px;margin-left:20px;margin-right:20px;'>：</span><input id='blue_score' style='width:75px;'></div></div>";
	            	
	    			art.dialog({
	                    title: "更新比分",
	                    icon: '',
	                    content: contentHtml,
	                    close: function () {
	                        $_this.focus(); //关闭时让触发弹窗的元素获取焦点
	                        return true;
	                    },
	                    okVal:"确定",
	                    ok: function () {
	                    	var red_score = $('#red_score').val();
	                    	var blue_score = $('#blue_score').val();
	                    	if(red_score == '' || blue_score == ''){
	                    		layer.msg('请输入比赛结果！');
	                    		return false;
	                    	}
	                    	
	                    	var g = /^[1-9]*[1-9][0-9]*$/;
	                        if(!g.test(red_score)){
	                        	layer.msg('请输入整数！');
	                    		return false;
	                        }
	                        if(!g.test(blue_score)){
	                        	layer.msg('请输入整数！');
	                    		return false;
	                        }
	                    	
	                    	art.dialog({
	                            title: false,
	                            icon: 'question',
	                            content: '您确定要将比分设定为 ' + red_score+ '（' + data.info.red.real_name + '）：' + blue_score + '（' + data.info.blue.real_name+'）吗？',
	                            close: function () {
	                            },
	                            okVal:"确定",
	                            ok: function () {
	                            	$.getJSON(href+'&live_id=' + live_id+'&red_score='+red_score+'&blue_score='+blue_score).done(function (data) {
	                                    if (data.state === 'success') {
	                                        if (data.referer) {
	                                            location.href = data.referer;
	                                        } else {
	                                            reloadPage(window);
	                                        }
	                                    } else if (data.state === 'fail') {
	    				    				art.dialog({   
	    				    					content: data.info,
	    				    					icon: 'warning',  
	    				    					ok: function () {   
	    				    						this.title(data.info);   
	    				    						return true;   
	    				    					}
	    				    				}); 
	                                    }
	                                });
	                                return true;
	                            },
	                            cancelVal: '关闭',
	                            cancel: true
	                        });
	                    },
	                    cancelVal: '关闭',
	                    cancel: true
	                });
	            }
	        });
		});
		
		$('.set_status').click(function(e){
			e.preventDefault();
			$_this = this;
			var live_id = $($_this).attr('data-id');
			var status = $($_this).attr('data-status');
			
			var href = $($_this).prop('href');
			
			var contentHtml = "<select id='update_status' style='width:180px;'><option value='0'>--请选择--</option>";
			
			if(2 == status){
				contentHtml += "<option value='4' id='status_option_4'>正在直播</option><option value='5' id='status_option_5'>直播回顾</option>";
			}else if(4 == status){
				contentHtml += "<option value='2' id='status_option_2'>直播结束</option><option value='5' id='status_option_5'>直播回顾</option>";
			}else{
				contentHtml += "<option value='4' id='status_option_4'>正在直播</option><option value='2' id='status_option_2'>直播结束</option>";
			}
        	contentHtml += "</select>";
        	
			art.dialog({
                title: "更新状态",
                icon: '',
                content: contentHtml,
                close: function () {
                    $_this.focus(); //关闭时让触发弹窗的元素获取焦点
                    return true;
                },
                okVal:"确定",
                ok: function () {
                	var update_status = $('#update_status').val();
                	if(update_status == 0){
                		layer.msg('请选择直播状态！');
                		return false;
                	}
                	var status_text = $('#status_option_'+update_status).text();
                	art.dialog({
                        title: false,
                        icon: 'question',
                        content: '您确定要将直播状态设置为【' + status_text +'】吗？',
                        close: function () {
                        },
                        okVal:"确定",
                        ok: function () {
                        	$.getJSON(href+'&live_id=' + live_id+'&status='+update_status).done(function (data) {
                                if (data.state === 'success') {
                                    if (data.referer) {
                                        location.href = data.referer;
                                    } else {
                                        reloadPage(window);
                                    }
                                } else if (data.state === 'fail') {
				    				art.dialog({   
				    					content: data.info,
				    					icon: 'warning',  
				    					ok: function () {   
				    						this.title(data.info);   
				    						return true;   
				    					}
				    				}); 
                                }
                            });
                            return true;
                        },
                        cancelVal: '关闭',
                        cancel: true
                    });
                },
                cancelVal: '关闭',
                cancel: true
            });
		});
		
		
	});
	
	function refresh_news(news_id){
	    $.post("<?php echo U('Admin/Live/refreshLiveTime')?>",{news_id:news_id}, function(result){
	        if(result >= 1){
	            var msg = '刷新成功';
	        }else{
	            var msg = '刷新失败';
	        }
	        alert(msg);
	        window.location.reload();
	    });
	}
	
	function update_live_count(type_id,type){
        if(type == 'live'){
            edit_column = $("#edit_weight_"+type_id).html();
            column_befor = $("#old_weight_"+type_id).val();//原权重值
            column  = $("#weight"+type_id).val(); //现权重值
            now_input_type = $("#weight" + type_id); //权重 ID
            now_edit_type  = $("#edit_weight_" + type_id);  //修改 按钮ID
			live_id = type_id;
        }

        if(edit_column == "修改"){
            //处理 同时存在多个input编辑问题
            $(".input_edit").attr("disabled", "disabled");
            $(".edit_sub").html("修改");

            now_input_type.removeAttr("disabled");
            now_edit_type.html("确认");
        }else{
            if(column_befor == name){
                now_input_type.attr("disabled", "disabled");
                now_edit_type.html("修改");
            }else {
				$.ajax({  
					type: "POST",  
					cache: false,  
					data: "type="+type+"&live_id="+live_id+"&old_val="+column_befor+"&val="+column,  
					async: false,
					url: "<?php echo U('Live/editLiveCount');?>",  
					success: function(ret) {
						if(ret['code'] == 200){
							now_input_type.attr("disabled", "disabled");
							now_edit_type.html("修改");
							location.reload()
						}else{
							alert(ret.msg)
						}
					}, error: function(data) {  
						alert('网络错误，请稍后再试！');
					}  
				}); 
            }
        }
    }
	
	function update_weight(news_id){
        edit_column = $("#live_edit_weight_"+news_id).html();
        column_befor = $("#live_old_weight_"+news_id).val();//原权重值
        column  = $("#live_weight"+news_id).val(); //现权重值
        now_input_type = $("#live_weight" + news_id); //权重 ID
        now_edit_type  = $("#live_edit_weight_" + news_id);  //修改 按钮ID
        
        if(edit_column == "修改"){
            //处理 同时存在多个input编辑问题
            $(".live_input_edit").attr("disabled", "disabled");
            $(".live_edit_sub").html("修改");
          
            now_input_type.removeAttr("disabled");
            now_edit_type.html("确认");
        }else{
            if(column_befor == column){
                now_input_type.attr("disabled", "disabled");
                now_edit_type.html("修改");
            }else {
                $.post("<?php echo U('Live/changeWeight');?>", {weight: column, live_id: news_id},
                        function (result) {
                            if (result == 1) {
                                now_input_type.attr("disabled", "disabled");
                                now_edit_type.html("修改");
                                location.reload()
                            }else{
                                alert("异常!")
                            }
                        }
                );
            }
        }
        $("#live_weight"+news_id).removeAttr("disabled");
    }
	
	</script>
</body>
</html>